﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using KenLib.BusinessManager;
using DataInfo;
using System.Web.Services;

public partial class Org_frmO_HistoryInfoInput : System.Web.UI.Page
{
    本社履歴Manager _本社履歴Manager = new 本社履歴Manager();
    ErrorManager _ErrorManager = new ErrorManager();

    /// <summary>
    /// Coder: Thanh Dong
    /// Event: Page load
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void Page_Load(object sender, EventArgs e)
    {

        ((Org_MasterPage)this.Master).changeTitle("本社履歴情報登録");
        ((Org_MasterPage)this.Master).HideLiArea("frmO_HistoryInfoInput");
        //Empty text
        RFV_年度.ErrorMessage = GetError("ER00001");
        RFV_ddl_決算月.ErrorMessage = GetError("ER00007");
        RFV_男性1.ErrorMessage = GetError("ER00001");
        RFV_女性1.ErrorMessage = GetError("ER00001");
        RFV_男性2.ErrorMessage = GetError("ER00001");
        RFV_女性2.ErrorMessage = GetError("ER00001");
        RFV_男性3.ErrorMessage = GetError("ER00001");
        RFV_女性3.ErrorMessage = GetError("ER00001");
        RFV_加入組合員数.ErrorMessage = GetError("ER00001");
        //CV_年度1.ErrorMessage = GetError("ER00002");
        CV_年度2.ErrorMessage = GetError("ER00009");
        CV_ddl_決算月1.ErrorMessage = GetError("ER00005");
        CV_ddl_決算月2.ErrorMessage = GetError("ER00009");
        ddl_年度.Focus();
        if (!IsPostBack)
        {

            Session["frmO_HistoryInfoInput_Refresh"] = Server.UrlEncode(System.DateTime.Now.ToString());
            Load_ddl_年度();
            ViewState["indexPage"] = 0;
            //Get 企業ID from frmO_BasicInfoInputCheck
            //Gan cung Session["frmO_BasicInfoInputCheck_企業ID"] = 123
            //Session["frmO_BasicInfoInputCheck_企業ID"] = 189;
            //Get ID from frmO_BasicInfoRef
            //Gan cung Session["frmO_BasicInfoRef_ID"] 
            //Session["frmO_BasicInfoRef_ID"] = 7;
            //Session["frmO_BasicInfoRef_企業ID"] = 189;
            if (Session["frmO_BasicInfoInputCheck_企業ID"] != null && Session["frmO_BasicInfoInputCheck_企業ID"].ToString() != "")
            {
                //Mode Insert 
                HiddenField_ShowText.Value = "insert";
                StatusButton(true);
                Session["frmO_HistoryInfoInput_Mode"] = "insert";
            }
            else if (Session["frmO_BasicInfoRef_ID"] != null && Session["frmO_BasicInfoRef_ID"].ToString() != "" && Session["frmO_BasicInfoRef_企業ID"] != null && Session["frmO_BasicInfoRef_企業ID"].ToString() != "")
            {
                //Mode update 
                HiddenField_ShowText.Value = "update";
                StatusButton(false);
                Session["frmO_HistoryInfoInput_Mode"] = "update";
            }
            else
            {
                Response.Redirect("frmO_BasicInfoInputCheck.aspx");
            }


            if (Session["frmO_HistoryInfoInput_Mode"].ToString() == "insert")
            {
                int 企業ID = Convert.ToInt32(Session["frmO_BasicInfoInputCheck_企業ID"]);
                ShowGridWithModeInsert(企業ID);
                HiddenField_ShowText.Value = "insert";
                StatusButton(true);
            }
            else
            {
                //update
                int 企業ID = Convert.ToInt32(Session["frmO_BasicInfoRef_企業ID"]);
                int ID = Convert.ToInt32(Session["frmO_BasicInfoRef_ID"]);
                DataTable dt = frmO_HistoryInfoInput_Select_本社履歴_ByID(ID);
                if (dt.Rows.Count > 0)
                {
                    //Show data in lable
                    //txt_年度.Text = dt.Rows[0]["年度"].ToString();
                    if (dt.Rows[0]["年度"].ToString() == "")
                    {
                        ddl_年度.SelectedValue = "-1";
                    }
                    else
                    {
                        int item = Convert.ToInt32(dt.Rows[0]["年度"]);
                        ListItem lst = ddl_年度.Items.FindByValue(item.ToString());
                        ddl_年度.SelectedIndex = ddl_年度.Items.IndexOf(lst);
                    }
                    if (dt.Rows[0]["決算月"].ToString() == "")
                    {
                        ddl_決算月.SelectedValue = "-1";
                    }
                    else
                    {
                        int temp = Convert.ToInt32(dt.Rows[0]["決算月"]);
                        ListItem lst = ddl_決算月.Items.FindByValue(temp.ToString());
                        ddl_決算月.SelectedIndex = ddl_決算月.Items.IndexOf(lst);
                    }
                    txt_男性1.Text = dt.Rows[0]["男性1"].ToString();
                    txt_女性1.Text = dt.Rows[0]["女性1"].ToString();
                    txt_男性2.Text = dt.Rows[0]["男性2"].ToString();
                    txt_女性2.Text = dt.Rows[0]["女性2"].ToString();
                    txt_男性3.Text = dt.Rows[0]["男性3"].ToString();
                    txt_女性3.Text = dt.Rows[0]["女性3"].ToString();
                    txt_加入組合員数.Text = dt.Rows[0]["加入組合員数"].ToString();
                    ////Session["frmO_BasicInfoRef_ID"] = Convert.ToInt32(dt.Rows[0]["ID"]);
                    //ShowGridWithModeUpdate(企業ID);
                    //StatusButton(false);
                }
                //DataTable dt = new DataTable();
                ShowGridWithModeUpdate(企業ID);
                HiddenField_ShowText.Value = "update";
                StatusButton(false);
            }
        }
    }

    /// <summary>
    /// Coder: Thanh Dong
    /// Event: Page PreRender
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void Page_PreRender(object sender, EventArgs e)
    {
        ViewState["frmO_HistoryInfoInput_Refresh"] = Session["frmO_HistoryInfoInput_Refresh"];
    }

    /// <summary>
    /// Coder: Thanh Dong
    /// Function: Get error message from id
    /// </summary>
    /// <param name="errorid"></param>
    /// <returns></returns>
    public String GetError(string errorid)
    {
        string error = "";
        Error er = new Error();
        er.ErrorID = errorid;
        ErrorManager frm_error = new ErrorManager();
        DataTable dt = frm_error.getError(er);
        if (dt.Rows.Count > 0)
        {
            error = dt.Rows[0][2].ToString();
        }
        return error;
    }

    /// <summary>
    /// Coder: Thanh Dong
    /// Function: Show girdview empty
    /// </summary>
    /// <param name="grv"></param>
    /// <param name="strTableHeader"></param>
    /// <param name="strEmpty"></param>
    public void ShowGridViewNotClassEmpty(GridView grv, string strTableHeader, string strEmpty)
    {
        DataTable dt = new DataTable();
        string[] arrColumnNames = strTableHeader.Split(',');
        foreach (string str in arrColumnNames)
        {
            dt.Columns.Add(str);
        }
        grv.ShowFooter = false;
        DataRow r = dt.NewRow();
        dt.Rows.InsertAt(r, 0);
        grv.DataSource = dt;
        grv.DataBind();
        grv.Rows[0].Cells.Clear();
        TableCell cell = new TableCell();
        cell.ColumnSpan = grv.Columns.Count + 1;
        cell.Text = strEmpty;
        grv.Rows[0].Cells.Add(cell);

    }

    /// <summary>
    /// Coder: Thanh Dong
    /// Function: Merged column show header gridview
    /// </summary>
    /// <param name="objgridviewrow"></param>
    /// <param name="objtablecell"></param>
    /// <param name="colspan"></param>
    /// <param name="rowspan"></param>
    /// <param name="celltext"></param>
    public void AddMergedRowCells(GridViewRow objgridviewrow, TableHeaderCell objtablecell, int colspan, int rowspan, string celltext)
    {
        objtablecell = new TableHeaderCell();
        objtablecell.Text = celltext;
        objtablecell.ColumnSpan = colspan;
        objtablecell.RowSpan = rowspan;
        objgridviewrow.Cells.Add(objtablecell);
    }

    /// <summary>
    /// Coder: Thanh Dong
    /// Event: Create column heeader in gridview
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void grv_RowCreated(object sender, GridViewRowEventArgs e)
    {
        DataTable dt = new DataTable();
        grv_本社履歴情報一覧.DataSource = dt;
        if (e.Row.RowType == DataControlRowType.Header)
        {
            GridView objGridView = (GridView)sender;
            GridViewRow objgridviewrow = new GridViewRow(1, 0, DataControlRowType.Header, DataControlRowState.Insert);
            TableHeaderCell objtablecell = new TableHeaderCell();
            AddMergedRowCells(objgridviewrow, objtablecell, 1, 2, "年度");
            AddMergedRowCells(objgridviewrow, objtablecell, 1, 2, "決算月");
            AddMergedRowCells(objgridviewrow, objtablecell, 2, 1, "常勤事務");
            AddMergedRowCells(objgridviewrow, objtablecell, 2, 1, "非常勤事務");
            AddMergedRowCells(objgridviewrow, objtablecell, 2, 1, "従事者");
            AddMergedRowCells(objgridviewrow, objtablecell, 1, 2, "加入組合員数");
            objGridView.Controls[0].Controls.AddAt(0, objgridviewrow);
        }
    }

    /// <summary>
    /// Coder: Thanh Dong
    /// Function: Change status button 更新 and button 登録
    /// </summary>
    /// <param name="status"></param>
    public void StatusButton(bool status)
    {
        btn_更新.Visible = !status;
        btn_登録.Visible = status;
        if (status)
        {
            btn_リセット.Text = "リセット";
        }
        else
        {
            btn_リセット.Text = "クリア";
        }
    }

    /// <summary>
    /// Coder: Thanh Dong
    /// Function: Data with mode insert
    /// </summary>
    /// <param name="企業ID"></param>
    /// <returns></returns>
    public DataTable frmO_HistoryInfoInput_Select_本社履歴(int 企業ID)
    {
        DataTable dt = new DataTable();
        dt = _本社履歴Manager.frmO_HistoryInfoInput_Select_本社履歴(企業ID);
        return dt;
    }

    /// <summary>
    /// Coder: Thanh Dong
    /// Function: Show data in gridview with mode insert
    /// </summary>
    /// <param name="企業ID"></param>
    public void ShowGridWithModeInsert(int 企業ID)
    {
        DataTable dt = frmO_HistoryInfoInput_Select_本社履歴(企業ID);
        grv_本社履歴情報一覧.DataSource = dt;
        if (dt.Rows.Count > 0)
        {
            grv_本社履歴情報一覧.DataBind();
            grv_本社履歴情報一覧.HeaderRow.Cells[0].Visible = false;
            grv_本社履歴情報一覧.HeaderRow.Cells[1].Visible = false;
            grv_本社履歴情報一覧.HeaderRow.Cells[8].Visible = false;
        }
        else
        {
            string strHeader = "年度,決算月,男性1,女性1,男性2,女性2,男性3,女性3,加入組合員数,ID";
            ShowGridViewNotClassEmpty(grv_本社履歴情報一覧, strHeader, "データがありません。");
            grv_本社履歴情報一覧.HeaderRow.Cells[0].Visible = false;
            grv_本社履歴情報一覧.HeaderRow.Cells[1].Visible = false;
            grv_本社履歴情報一覧.HeaderRow.Cells[8].Visible = false;
        }
    }

    /// <summary>
    /// Coder: Thanh Dong
    /// Function: Data with mode update
    /// </summary>
    /// <param name="ID"></param>
    /// <returns></returns>
    public DataTable frmO_HistoryInfoInput_Select_本社履歴_ByID(int ID)
    {
        DataTable dt = new DataTable();
        dt = _本社履歴Manager.frmO_HistoryInfoInput_Select_本社履歴_ByID(ID);
        return dt;
    }

    /// <summary>
    /// Coder: Thanh Dong
    /// Function: Show data in gridview with mode update
    /// </summary>
    /// <param name="企業ID"></param>
    public void ShowGridWithModeUpdate(int 企業ID)
    {
        DataTable dt = frmO_HistoryInfoInput_Select_本社履歴(企業ID);
        grv_本社履歴情報一覧.DataSource = dt;
        if (dt.Rows.Count > 0)
        {
            grv_本社履歴情報一覧.DataBind();
            grv_本社履歴情報一覧.HeaderRow.Cells[0].Visible = false;
            grv_本社履歴情報一覧.HeaderRow.Cells[1].Visible = false;
            grv_本社履歴情報一覧.HeaderRow.Cells[8].Visible = false;

        }
        else
        {
            string strHeader = "年度,決算月,男性1,女性1,男性2,女性2,男性3,女性3,加入組合員数,ID";
            ShowGridViewNotClassEmpty(grv_本社履歴情報一覧, strHeader, "データがありません。");
            grv_本社履歴情報一覧.HeaderRow.Cells[0].Visible = false;
            grv_本社履歴情報一覧.HeaderRow.Cells[1].Visible = false;
            grv_本社履歴情報一覧.HeaderRow.Cells[8].Visible = false;
        }
    }

    /// <summary>
    /// Coder: Thanh Dong
    /// Function: Check insert data to table 本社履歴 true or false
    /// </summary>
    /// <param name="_本社履歴"></param>
    /// <returns></returns>
    public int frmO_HistoryInfoInput_Insert_本社履歴(本社履歴 _本社履歴)
    {
        if (_本社履歴Manager.frmO_HistoryInfoInput_Insert_本社履歴(_本社履歴) == 1)
        {
            return 1;
        }
        return 0;
    }

    /// <summary>
    /// Coder: Thanh Dong
    /// Function: Check update data to table 本社履歴 true or false
    /// </summary>
    /// <param name="_本社履歴"></param>
    /// <returns></returns>

    public int frmO_HistoryInfoInput_update_本社履歴(本社履歴 _本社履歴)
    {
        if (_本社履歴Manager.frmO_HistoryInfoInput_update_本社履歴(_本社履歴) == 1)
        {
            return 1;
        }
        return 0;
    }

    /// <summary>
    /// Coder: Thanh Dong
    /// Function: Get object type 本社履歴
    /// </summary>
    /// <returns></returns>
    public 本社履歴 Get本社履歴()
    {
        本社履歴 _本社履歴 = new 本社履歴();
        _本社履歴.年度 = Convert.ToInt32(ddl_年度.SelectedValue);
        _本社履歴.決算月 = Convert.ToString(ddl_決算月.SelectedValue);
        _本社履歴.常勤事務男 = Convert.ToInt32(txt_男性1.Text);
        _本社履歴.常勤事務女 = Convert.ToInt32(txt_女性1.Text);
        _本社履歴.常勤現場男 = Convert.ToInt32(txt_男性2.Text);
        _本社履歴.常勤現場女 = Convert.ToInt32(txt_女性2.Text);
        _本社履歴.従事者数男 = Convert.ToInt32(txt_男性3.Text);
        _本社履歴.従事者数女 = Convert.ToInt32(txt_女性3.Text);
        _本社履歴.加入している組合員数 = Convert.ToInt32(txt_加入組合員数.Text);
        if (Session["frmO_HistoryInfoInput_Mode"].ToString() == "update")
        {
            if (Session["frmO_BasicInfoRef_ID"] != null && Session["frmO_BasicInfoRef_ID"].ToString() != "")
            {
                _本社履歴.ID = Convert.ToInt32(Session["frmO_BasicInfoRef_ID"]);
                _本社履歴.企業ID = Convert.ToInt32(Session["frmO_BasicInfoRef_企業ID"]);
                HiddenField_ShowText.Value = "update";
            }
        }
        else
        {
            // Update cua mode insert
            if (Session["frmO_HistoryInfoInput_ID"] != null && Session["frmO_HistoryInfoInput_ID"].ToString() != "")
            {
                //Nhay vao truong hop mode insert cua update
                _本社履歴.ID = Convert.ToInt32(Session["frmO_HistoryInfoInput_ID"]);
                HiddenField_ShowText.Value = "update";
            }
            _本社履歴.企業ID = Convert.ToInt32(Session["frmO_BasicInfoInputCheck_企業ID"]);
            _本社履歴.廃止区分 = 0;
        }
        return _本社履歴;
    }

    /// <summary>
    /// Coder: Thanh Dong
    /// Event: Insert data to table 本社履歴
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btn_登録_Click(object sender, EventArgs e)
    {
        HiddenField_ShowText.Value = "insert";
        if (Page.IsValid == true)
        {
            本社履歴 _本社履歴 = Get本社履歴();
            if (Session["frmO_HistoryInfoInput_Refresh"].ToString() == ViewState["frmO_HistoryInfoInput_Refresh"].ToString())
            {
                if (frmO_HistoryInfoInput_Insert_本社履歴(_本社履歴) == 1)
                {
                    ClearText();
                    ShowGridWithModeInsert(Convert.ToInt32(Session["frmO_BasicInfoInputCheck_企業ID"]));
                    Session["frmO_HistoryInfoInput_Refresh"] = Server.UrlEncode(System.DateTime.Now.ToString());
                }
                else
                {
                    ClientScript.RegisterStartupScript(this.GetType(), "alert", "<script>alert('データベースに接続ができません');</script>");
                    return;
                }
            }
            else
            {
                ClearText();
                ShowGridWithModeInsert(Convert.ToInt32(Session["frmO_BasicInfoInputCheck_企業ID"]));
            }
        }
        


    }

    /// <summary>
    /// Coder: Thanh Dong
    /// Function: Clear text in textbox and dropdownlist
    /// </summary>
    public void ClearText()
    {
        ddl_年度.SelectedValue = "-1";
        ddl_年度.Focus();
        ddl_決算月.SelectedValue = "-1";
        txt_男性1.Text = "";
        txt_女性1.Text = "";
        txt_男性2.Text = "";
        txt_女性2.Text = "";
        txt_男性3.Text = "";
        txt_女性3.Text = "";
        txt_加入組合員数.Text = "";
    }

    /// <summary>
    /// Coder: Thanh Dong
    /// Event: Update data in table 本社履歴
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btn_更新_Click(object sender, EventArgs e)
    {
        if (Page.IsValid==true)
        {
            HiddenField_ShowText.Value = "update";

            //ClientScript.RegisterStartupScript(GetType(), "Javascript", "javascript: CheckExists_年度1(); ", true);
            //ClientScript.RegisterStartupScript(GetType(), "Javascript", "javascript: CheckExists_年度_決算月1(); ", true);

            本社履歴 _本社履歴 = Get本社履歴();
            if (frmO_HistoryInfoInput_update_本社履歴(_本社履歴) == 1)
            {
                if (Session["frmO_HistoryInfoInput_Mode"].ToString() == "update")
                {
                    int ID = Convert.ToInt32(Session["frmO_BasicInfoRef_ID"]);
                    DataTable dt = frmO_HistoryInfoInput_Select_本社履歴_ByID(ID);
                    if (dt.Rows.Count > 0)
                    {
                        //Show data in lable
                        if (dt.Rows[0]["年度"].ToString() == "")
                        {
                            ddl_年度.SelectedValue = "-1";
                        }
                        else
                        {
                            int item = Convert.ToInt32(dt.Rows[0]["年度"]);
                            ListItem lst = ddl_年度.Items.FindByValue(item.ToString());
                            ddl_年度.SelectedIndex = ddl_年度.Items.IndexOf(lst);
                        }
                        if (dt.Rows[0]["決算月"].ToString() == "")
                        {
                            ddl_決算月.SelectedValue = "-1";
                        }
                        else
                        {
                            int temp = Convert.ToInt32(dt.Rows[0]["決算月"]);
                            ListItem lst = ddl_決算月.Items.FindByValue(temp.ToString());
                            ddl_決算月.SelectedIndex = ddl_決算月.Items.IndexOf(lst);
                        }
                        txt_男性1.Text = dt.Rows[0]["男性1"].ToString();
                        txt_女性1.Text = dt.Rows[0]["女性1"].ToString();
                        txt_男性2.Text = dt.Rows[0]["男性2"].ToString();
                        txt_女性2.Text = dt.Rows[0]["女性2"].ToString();
                        txt_男性3.Text = dt.Rows[0]["男性3"].ToString();
                        txt_女性3.Text = dt.Rows[0]["女性3"].ToString();
                        txt_加入組合員数.Text = dt.Rows[0]["加入組合員数"].ToString();
                    }
                    ShowGridWithModeUpdate(Convert.ToInt32(Session["frmO_BasicInfoRef_企業ID"]));
                    StatusButton(false);

                }
                else
                {
                    Session.Remove("frmO_HistoryInfoInput_ID");
                    Response.Redirect("frmO_HistoryInfoInput.aspx");
                }
            }
            else
            {
                //Khong cap nhat duoc du lieu
                ClientScript.RegisterStartupScript(this.GetType(), "alert", "<script>alert('データベースに接続ができません');</script>");
                return;
            }
        }
    }

    /// <summary>
    /// Coder: Thanh Dong
    /// Event: Button 戻る
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btn_戻る_Click(object sender, EventArgs e)
    {
        if (Session["frmO_HistoryInfoInput_Mode"].ToString() == "insert")
        {
            Session.Remove("frmO_HistoryInfoInput_Mode");
            Session.Remove("frmO_BasicInfoInputCheck_企業ID");
            Session.Remove("frmO_HistoryInfoInput_ID");
            Response.Redirect("frmO_BasicInfoInput.aspx");
        }
        else
        {
            Session.Remove("frmO_HistoryInfoInput_Mode");
            Session.Remove("frmO_BasicInfoInputCheck_企業ID");
            Session.Remove("frmO_BasicInfoRef_ID");
            Response.Redirect("frmO_BasicInfoRef.aspx");
        }
    }

    /// <summary>
    /// Coder: Thanh Dong
    /// Event: Button 次
    /// Note: Not finish
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btn_次_Click(object sender, EventArgs e)
    {
        //Param for frmO_BranchInfoInput.aspx
        //Hien tai chua co form nay nen ko cho link toi form nay
        //Session["frmO_HistoryInfoInput_企業ID"] = Convert.ToInt32(Session["frmO_BasicInfoInputCheck_企業ID"]);
        //Session.Remove("frmO_HistoryInfoInput_Mode");
        //Session.Remove("frmO_BasicInfoInputCheck_企業ID");
        //Session.Remove("frmO_BasicInfoRef_ID");
        //Response.Redirect("frmO_BranchInfoInput.aspx");
        ClientScript.RegisterStartupScript(this.GetType(), "alert", "<script>alert('この部分がまだ作成していません');</script>");
        return;
    }

    /// <summary>
    /// Coder: Thanh Dong
    /// Event: Row data bound
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void grv_本社履歴情報一覧_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Attributes.Add("onclick", "javascript:__doPostBack('ctl00$ContentPlaceHolder1$grv_本社履歴情報一覧','Load$0" + e.Row.RowIndex + "')");
        }
    }

    /// <summary>
    /// Coder: Thanh Dong
    /// Event: Row Command
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void grv_本社履歴情報一覧_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName.Equals("Load"))
        {
            if (Session["frmO_HistoryInfoInput_Mode"].ToString() == "insert")
            {
                int 企業ID = Convert.ToInt32(Session["frmO_BasicInfoInputCheck_企業ID"]);
                DataTable dt = frmO_HistoryInfoInput_Select_本社履歴(企業ID);
                if (dt.Rows.Count > 0)
                {
                    int pagecurrent = Int32.Parse(ViewState["indexPage"].ToString());
                    int index;
                    if (pagecurrent == 0)
                    {
                        index = Int32.Parse(e.CommandArgument.ToString());
                    }
                    else
                    {
                        index = Convert.ToInt32(e.CommandArgument) + pagecurrent * 10;
                    }

                    //Show data in lable
                    //txt_年度.Text = dt.Rows[index]["年度"].ToString();
                    if (dt.Rows[index]["年度"].ToString() == "")
                    {
                        ddl_年度.SelectedValue = "-1";
                    }
                    else
                    {
                        int item = Convert.ToInt32(dt.Rows[index]["年度"]);
                        ListItem lst = ddl_年度.Items.FindByValue(item.ToString());
                        ddl_年度.SelectedIndex = ddl_年度.Items.IndexOf(lst);
                    }
                    if (dt.Rows[index]["決算月"].ToString() == "")
                    {
                        ddl_決算月.SelectedValue = "-1";
                    }
                    else
                    {
                        int temp = Convert.ToInt32(dt.Rows[index]["決算月"]);
                        ListItem lst = ddl_決算月.Items.FindByValue(temp.ToString());
                        ddl_決算月.SelectedIndex = ddl_決算月.Items.IndexOf(lst);
                    }
                    txt_男性1.Text = dt.Rows[index]["男性1"].ToString();
                    txt_女性1.Text = dt.Rows[index]["女性1"].ToString();
                    txt_男性2.Text = dt.Rows[index]["男性2"].ToString();
                    txt_女性2.Text = dt.Rows[index]["女性2"].ToString();
                    txt_男性3.Text = dt.Rows[index]["男性3"].ToString();
                    txt_女性3.Text = dt.Rows[index]["女性3"].ToString();
                    txt_加入組合員数.Text = dt.Rows[index]["加入組合員数"].ToString();
                    //Id dung de update trong mode insert
                    Session["frmO_HistoryInfoInput_ID"] = Convert.ToInt32(dt.Rows[index]["ID"]);
                    ShowGridWithModeInsert(企業ID);
                    HiddenField_ShowText.Value = "update";
                    StatusButton(false);
                }
                else
                {
                    string strHeader = "年度,決算月,男性1,女性1,男性2,女性2,男性3,女性3,加入組合員数,ID";
                    ShowGridViewNotClassEmpty(grv_本社履歴情報一覧, strHeader, "データがありません。");
                    grv_本社履歴情報一覧.HeaderRow.Cells[0].Visible = false;
                    grv_本社履歴情報一覧.HeaderRow.Cells[1].Visible = false;
                    grv_本社履歴情報一覧.HeaderRow.Cells[8].Visible = false;
                    StatusButton(true);
                }

            }

            else if (Session["frmO_HistoryInfoInput_Mode"].ToString() == "update")
            {
                StatusButton(false);
                int 企業ID = 0;
                if (Session["frmO_BasicInfoRef_企業ID"] != null && Session["frmO_BasicInfoRef_企業ID"].ToString() != "")
                {
                    企業ID = Convert.ToInt32(Session["frmO_BasicInfoRef_企業ID"]);
                    DataTable dt = frmO_HistoryInfoInput_Select_本社履歴(企業ID);
                    if (dt.Rows.Count > 0)
                    {
                        int pagecurrent = Int32.Parse(ViewState["indexPage"].ToString());
                        int index;
                        if (pagecurrent == 0)
                        {
                            index = Int32.Parse(e.CommandArgument.ToString());
                        }
                        else
                        {
                            index = Convert.ToInt32(e.CommandArgument) + pagecurrent * 10;
                        }

                        //Show data in lable
                        //txt_年度.Text = dt.Rows[index]["年度"].ToString();
                        if (dt.Rows[index]["年度"].ToString() == "")
                        {
                            ddl_年度.SelectedValue = "-1";
                        }
                        else
                        {
                            int item = Convert.ToInt32(dt.Rows[index]["年度"]);
                            ListItem lst = ddl_年度.Items.FindByValue(item.ToString());
                            ddl_年度.SelectedIndex = ddl_年度.Items.IndexOf(lst);
                        }
                        if (dt.Rows[index]["決算月"].ToString() == "")
                        {
                            ddl_決算月.SelectedValue = "-1";
                        }
                        else
                        {
                            int temp = Convert.ToInt32(dt.Rows[index]["決算月"]);
                            ListItem lst = ddl_決算月.Items.FindByValue(temp.ToString());
                            ddl_決算月.SelectedIndex = ddl_決算月.Items.IndexOf(lst);
                        }
                        txt_男性1.Text = dt.Rows[index]["男性1"].ToString();
                        txt_女性1.Text = dt.Rows[index]["女性1"].ToString();
                        txt_男性2.Text = dt.Rows[index]["男性2"].ToString();
                        txt_女性2.Text = dt.Rows[index]["女性2"].ToString();
                        txt_男性3.Text = dt.Rows[index]["男性3"].ToString();
                        txt_女性3.Text = dt.Rows[index]["女性3"].ToString();
                        txt_加入組合員数.Text = dt.Rows[index]["加入組合員数"].ToString();
                        Session["frmO_BasicInfoRef_ID"] = Convert.ToInt32(dt.Rows[index]["ID"]);
                        Session["frmO_HistoryInfoInput_Mode"] = "update";
                        HiddenField_ShowText.Value = "update";
                        ShowGridWithModeUpdate(Convert.ToInt32(Session["frmO_BasicInfoRef_企業ID"]));
                    }
                    else
                    {
                        string strHeader = "年度,決算月,男性1,女性1,男性2,女性2,男性3,女性3,加入組合員数,ID";
                        ShowGridViewNotClassEmpty(grv_本社履歴情報一覧, strHeader, "データがありません。");
                        grv_本社履歴情報一覧.HeaderRow.Cells[0].Visible = false;
                        grv_本社履歴情報一覧.HeaderRow.Cells[1].Visible = false;
                        grv_本社履歴情報一覧.HeaderRow.Cells[8].Visible = false;
                    }
                }
            }

            else
            {
                string strHeader = "年度,決算月,男性1,女性1,男性2,女性2,男性3,女性3,加入組合員数,ID";
                ShowGridViewNotClassEmpty(grv_本社履歴情報一覧, strHeader, "データがありません。");
                grv_本社履歴情報一覧.HeaderRow.Cells[0].Visible = false;
                grv_本社履歴情報一覧.HeaderRow.Cells[1].Visible = false;
                grv_本社履歴情報一覧.HeaderRow.Cells[8].Visible = false;
            }
        }

    }

    /// <summary>
    /// Coder: Thanh Dong
    /// Event: Paging
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void grv_本社履歴情報一覧_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        //Chua dung sua lai
        if (Session["frmO_HistoryInfoInput_Mode"].ToString() == "insert")
        {
            int 企業ID = Convert.ToInt32(Session["frmO_BasicInfoInputCheck_企業ID"]);
            int index = e.NewPageIndex;
            ViewState["indexPage"] = index;
            grv_本社履歴情報一覧.PageIndex = index;
            ShowGridWithModeInsert(企業ID);
            if (Session["frmO_HistoryInfoInput_ID"] != null && Session["frmO_HistoryInfoInput_ID"].ToString() != "")
            {
                StatusButton(false);
            }
            else
            {
                StatusButton(true);
            }
        }
        else
        {
            //update
            int 企業ID;
            if (Session["frmO_BasicInfoRef_企業ID"] != null && Session["frmO_BasicInfoRef_企業ID"].ToString() != "")
            {
                企業ID = Convert.ToInt32(Session["frmO_BasicInfoRef_企業ID"]);
                int index = e.NewPageIndex;
                ViewState["indexPage"] = index;
                grv_本社履歴情報一覧.PageIndex = index;
                ShowGridWithModeUpdate(企業ID);
                StatusButton(false);
            }
        }
    }

    /// <summary>
    /// Coder: Thanh Dong
    /// Function: Check input 年度 true or false
    /// </summary>
    /// <param name="_年度"></param>
    /// <returns></returns>
    //[WebMethod]
    //public static string IsExisted1(string _年度)
    //{
    //    //System.Threading.Thread.Sleep(3000);
    //    int status = 0;
    //    int 企業ID = 0;
    //    //Mode insert
    //    if (HttpContext.Current.Session["frmO_HistoryInfoInput_Mode"].ToString() == "insert")
    //    {
    //        企業ID = Convert.ToInt32(HttpContext.Current.Session["frmO_BasicInfoInputCheck_企業ID"]);
    //    }
    //    else
    //    {
    //        //Mode update chua xu ly
    //        企業ID = Convert.ToInt32(HttpContext.Current.Session["frmO_BasicInfoRef_企業ID"]);
    //    }
    //    int temp = -1;
    //    int 年度 = Convert.ToInt32(_年度);

    //    temp = frmO_HistoryInfoInput_CheckExists_企業ID_設立年月日_Year(企業ID, 年度, out temp);
    //    if (temp == 1)
    //    {
    //        if (HttpContext.Current.Session["frmO_HistoryInfoInput_ID"] != null && HttpContext.Current.Session["frmO_HistoryInfoInput_ID"].ToString() != "")
    //        {
    //            DataTable dt = new 本社履歴Manager().frmO_HistoryInfoInput_CheckExists_企業ID_Year(企業ID, 年度);
    //            if (dt.Rows.Count > 0)
    //            {
    //                if (dt.Rows[0]["ID"].ToString() == HttpContext.Current.Session["frmO_HistoryInfoInput_ID"].ToString())
    //                {
    //                    status = 1;
    //                }
    //                else
    //                {
    //                    status = 0;
    //                }
    //            }
    //            else
    //            {
    //                status = 1;
    //            }
                
    //        }
    //        else
    //        {
    //            DataTable dt = new 本社履歴Manager().frmO_HistoryInfoInput_CheckExists_企業ID_Year(企業ID, 年度);
    //            if (dt.Rows.Count > 0)
    //            {
    //                status = 0;
    //            }
    //            else
    //            {
    //                status = 1;
    //            }
    //        }
    //    }
    //    return status.ToString();
    //}

    /// <summary>
    /// Coder: Thanh Dong
    /// Function: Check input 年度, 決算月 true or false
    /// </summary>
    /// <param name="_年度"></param>
    /// <param name="_決算月"></param>
    /// <returns></returns>
    [WebMethod]
    //public static string IsExisted2(string _年度, string _決算月)
    //{
    //    int status = 0;
    //    //Mode insert
    //    //System.Threading.Thread.Sleep(3000);

    //    int 年度 = Convert.ToInt32(_年度);
    //    int 決算月 = Convert.ToInt32(_決算月);
    //    if (HttpContext.Current.Session["frmO_HistoryInfoInput_Mode"].ToString() == "insert")
    //    {
    //        //Update of mode insert
    //        if (HttpContext.Current.Session["frmO_HistoryInfoInput_ID"] != null && HttpContext.Current.Session["frmO_HistoryInfoInput_ID"].ToString() != "")
    //        {
    //            int ID;
    //            ID = Convert.ToInt32(HttpContext.Current.Session["frmO_HistoryInfoInput_ID"]);
    //            int temp = -1;
    //            int 企業ID = Convert.ToInt32(HttpContext.Current.Session["frmO_BasicInfoInputCheck_企業ID"]);
    //            temp = frmO_HistoryInfoInput_Check_Insert(企業ID, 年度, 決算月, out temp);
    //            if (temp == 9)
    //            {
    //                DataTable dt = frmO_HistoryInfoInput_GetID(企業ID, 年度, 決算月);
    //                if (ID != Convert.ToInt32(dt.Rows[0]["ID"]))
    //                {
    //                    status = 9;
    //                }
    //                else
    //                {
    //                    status = 1;
    //                }
    //            }
    //            else if (temp == 5)
    //            {
    //                status = 5;
    //            }
    //            else
    //            {
    //                status = 1;
    //            }
    //        }
    //        else
    //        {
    //            int 企業ID = Convert.ToInt32(HttpContext.Current.Session["frmO_BasicInfoInputCheck_企業ID"]);
    //            int temp = -1;
    //            temp = frmO_HistoryInfoInput_Check_Insert(企業ID, 年度, 決算月, out temp);
    //            if (temp == 5)
    //            {
    //                status = 5;
    //            }
    //            else if (temp == 9)
    //            {
    //                status = 9;
    //            }
    //            else
    //            {
    //                //Day la truong hop dung
    //                DataTable dt = new 本社履歴Manager().frmO_HistoryInfoInput_CheckExists_企業ID_Year(企業ID, 年度);
    //                if (dt.Rows.Count > 0)
    //                {
    //                    status = 5;
    //                }
    //                else
    //                {
    //                    status = 1;
    //                }
    //            }
    //        }
    //    }
    //    else
    //    {
    //        // Mode update chua xu ly
    //        int ID;
    //        if (HttpContext.Current.Session["frmO_BasicInfoRef_ID"] != null && HttpContext.Current.Session["frmO_BasicInfoRef_ID"].ToString() != "")
    //        {
    //            ID = Convert.ToInt32(HttpContext.Current.Session["frmO_BasicInfoRef_ID"]);
    //            int 企業ID = Convert.ToInt32(HttpContext.Current.Session["frmO_BasicInfoRef_企業ID"]);
    //            int temp = -1;
    //            temp = frmO_HistoryInfoInput_Check_Insert(企業ID, 年度, 決算月, out temp);
    //            if (temp == 9)
    //            {
    //                DataTable dt = frmO_HistoryInfoInput_GetID(企業ID, 年度, 決算月);
    //                if (ID != Convert.ToInt32(dt.Rows[0]["ID"]))
    //                {
    //                    status = 9;
    //                }
    //                else
    //                {
    //                    status = 1;
    //                }
    //            }
    //            else if (temp == 5)
    //            {
    //                status = 5;
    //            }
    //            else
    //            {
    //                status = 1;
    //            }
    //        }

    //    }
    //    return status.ToString();
    //}

  

    /// <summary>
    /// Coder: Thanh Dong
    /// Function: Get 1 record table 本社履歴 from ID
    /// </summary>
    /// <param name="企業ID"></param>
    /// <param name="年度"></param>
    /// <param name="決算月"></param>
    /// <returns></returns>
    public static DataTable frmO_HistoryInfoInput_GetID(int 企業ID, int 年度, int 決算月)
    {
        return new 本社履歴Manager().frmO_HistoryInfoInput_GetID(企業ID, 年度, 決算月);
    }

    /// <summary>
    /// Coder: Thanh Dong
    /// Event: Button リセット
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btn_リセット_Click(object sender, EventArgs e)
    {
        if (Session["frmO_HistoryInfoInput_Mode"].ToString() == "update")
        {
            Response.Redirect("frmO_HistoryInfoInput.aspx");
        }
        else
        {
            ddl_年度.SelectedValue = "-1";
            ddl_決算月.SelectedValue = "-1";
            txt_男性1.Text = "";
            txt_女性1.Text = "";
            txt_男性2.Text = "";
            txt_女性2.Text = "";
            txt_男性3.Text = "";
            txt_女性3.Text = "";
            txt_加入組合員数.Text = "";
        }
    }

    /// <summary>
    /// Coder: Thanh Dong
    /// Function: Check input 企業ID, 年度, 決算月 true or flase
    /// </summary>
    /// <param name="企業ID"></param>
    /// <param name="年度"></param>
    /// <param name="決算月"></param>
    /// <param name="temp"></param>
    /// <returns></returns>
    public static int frmO_HistoryInfoInput_Check_Insert(int 企業ID, int 年度, int 決算月, out int temp)
    {
        return new 本社情報Manager().frmO_HistoryInfoInput_Check_Insert(企業ID, 年度, 決算月, out temp);
    }

    /// <summary>
    /// Coder: Thanh Dong
    /// Function: Check input data 企業ID, 年度
    /// </summary>
    /// <param name="企業ID"></param>
    /// <param name="年度"></param>
    /// <param name="temp"></param>
    /// <returns></returns>
    public static int frmO_HistoryInfoInput_CheckExists_企業ID_設立年月日_Year(int 企業ID, int 年度, out int temp)
    {
        return new 本社情報Manager().frmO_HistoryInfoInput_CheckExists_企業ID_設立年月日_Year(企業ID, 年度, out temp);
    }


    /// <summary>
    /// Coder: Thanh Dong
    /// Function: Load data in 年度 YearNow - 10 -> YearNow
    /// </summary>
    public void Load_ddl_年度()
    {
        List<string> list = new List<string>();
        int int_YearNow = DateTime.Now.Year;
        for (int i = int_YearNow - 10; i <= int_YearNow; i++)
        {
            list.Add(i.ToString());
        }
        ddl_年度.DataSource = list;
        ddl_年度.DataBind();
        System.Web.UI.WebControls.ListItem item = new System.Web.UI.WebControls.ListItem("[選択]", "-1");
        item.Selected = true;
        ddl_年度.Items.Insert(0, item);
    }
    
    protected void CV_年度2_ServerValidate(object source, ServerValidateEventArgs args)
    {
        int 企業ID = 0;
        //Mode insert
        if (HttpContext.Current.Session["frmO_HistoryInfoInput_Mode"].ToString() == "insert")
        {
            企業ID = Convert.ToInt32(HttpContext.Current.Session["frmO_BasicInfoInputCheck_企業ID"]);
        }
        else
        {
            //Mode update chua xu ly
            企業ID = Convert.ToInt32(HttpContext.Current.Session["frmO_BasicInfoRef_企業ID"]);
        }
        int temp = -1;
        int 年度 = Convert.ToInt32(ddl_年度.SelectedValue);

        temp = frmO_HistoryInfoInput_CheckExists_企業ID_設立年月日_Year(企業ID, 年度, out temp);
        if (temp == 1)
        {
            if (HttpContext.Current.Session["frmO_HistoryInfoInput_ID"] != null && HttpContext.Current.Session["frmO_HistoryInfoInput_ID"].ToString() != "")
            {
                DataTable dt = new 本社履歴Manager().frmO_HistoryInfoInput_CheckExists_企業ID_Year(企業ID, 年度);
                if (dt.Rows.Count > 0)
                {
                    if (dt.Rows[0]["ID"].ToString() == HttpContext.Current.Session["frmO_HistoryInfoInput_ID"].ToString())
                    {
                        args.IsValid = true;
                    }
                    else
                    {
                        args.IsValid = false;
                        hd_年度.Value = ddl_年度.SelectedValue.ToString();
                    }
                }
                else
                {
                    args.IsValid = true;
                }

            }
            else
            {
                DataTable dt = new 本社履歴Manager().frmO_HistoryInfoInput_CheckExists_企業ID_Year(企業ID, 年度);
                if (dt.Rows.Count > 0)
                {
                    args.IsValid = false;
                    hd_年度.Value = ddl_年度.SelectedValue.ToString();
                }
                else
                {
                    args.IsValid = true;
                }
            }
        }
        else
        {
            args.IsValid = false;
            hd_年度.Value = ddl_年度.SelectedValue.ToString();
        }
        
    }
    
    protected void CV_ddl_決算月1_ServerValidate(object source, ServerValidateEventArgs args)
    {
        int 年度 = Convert.ToInt32(ddl_年度.SelectedValue);
        int 決算月 = Convert.ToInt32(ddl_決算月.SelectedValue);
        if (HttpContext.Current.Session["frmO_HistoryInfoInput_Mode"].ToString() == "insert")
        {
            //Update of mode insert
            if (HttpContext.Current.Session["frmO_HistoryInfoInput_ID"] != null && HttpContext.Current.Session["frmO_HistoryInfoInput_ID"].ToString() != "")
            {
                int ID;
                ID = Convert.ToInt32(HttpContext.Current.Session["frmO_HistoryInfoInput_ID"]);
                int temp = -1;
                int 企業ID = Convert.ToInt32(HttpContext.Current.Session["frmO_BasicInfoInputCheck_企業ID"]);
                temp = frmO_HistoryInfoInput_Check_Insert(企業ID, 年度, 決算月, out temp);
                //if (temp == 9)
                //{
                //    DataTable dt = frmO_HistoryInfoInput_GetID(企業ID, 年度, 決算月);
                //    if (ID != Convert.ToInt32(dt.Rows[0]["ID"]))
                //    {
                //        status = 9;
                //    }
                //    else
                //    {
                //        status = 1;
                //    }
                //}
                if (temp == 5)
                {
                    args.IsValid = false;
                    hd_決算月1.Value = ddl_決算月.SelectedValue.ToString();
                }
                else
                {
                    args.IsValid = true;
                }
            }
            else
            {
                int 企業ID = Convert.ToInt32(HttpContext.Current.Session["frmO_BasicInfoInputCheck_企業ID"]);
                int temp = -1;
                temp = frmO_HistoryInfoInput_Check_Insert(企業ID, 年度, 決算月, out temp);
                if (temp == 5)
                {
                    args.IsValid = false;
                    hd_決算月1.Value = ddl_決算月.SelectedValue.ToString();
                }
                //else if (temp == 9)
                //{
                //    status = 9;
                //}
                else
                {
                    //Day la truong hop dung
                    DataTable dt = new 本社履歴Manager().frmO_HistoryInfoInput_CheckExists_企業ID_Year(企業ID, 年度);
                    if (dt.Rows.Count > 0)
                    {
                        args.IsValid = false;
                        hd_決算月1.Value = ddl_決算月.SelectedValue.ToString();
                    }
                    else
                    {
                        args.IsValid = true;
                    }
                }
            }
        }
        else
        {
            // Mode update chua xu ly
            int ID;
            if (HttpContext.Current.Session["frmO_BasicInfoRef_ID"] != null && HttpContext.Current.Session["frmO_BasicInfoRef_ID"].ToString() != "")
            {
                ID = Convert.ToInt32(HttpContext.Current.Session["frmO_BasicInfoRef_ID"]);
                int 企業ID = Convert.ToInt32(HttpContext.Current.Session["frmO_BasicInfoRef_企業ID"]);
                int temp = -1;
                temp = frmO_HistoryInfoInput_Check_Insert(企業ID, 年度, 決算月, out temp);
                //if (temp == 9)
                //{
                //    DataTable dt = frmO_HistoryInfoInput_GetID(企業ID, 年度, 決算月);
                //    if (ID != Convert.ToInt32(dt.Rows[0]["ID"]))
                //    {
                //        status = 9;
                //    }
                //    else
                //    {
                //        status = 1;
                //    }
                //}
                if (temp == 5)
                {
                    args.IsValid = false;
                    hd_決算月1.Value = ddl_決算月.SelectedValue.ToString();
                }
                else
                {
                    args.IsValid = true;
                }
            }

        }
    }
    protected void CV_ddl_決算月2_ServerValidate(object source, ServerValidateEventArgs args)
    {
        int 年度 = Convert.ToInt32(ddl_年度.SelectedValue);
        int 決算月 = Convert.ToInt32(ddl_決算月.SelectedValue);
        if (HttpContext.Current.Session["frmO_HistoryInfoInput_Mode"].ToString() == "insert")
        {
            //Update of mode insert
            if (HttpContext.Current.Session["frmO_HistoryInfoInput_ID"] != null && HttpContext.Current.Session["frmO_HistoryInfoInput_ID"].ToString() != "")
            {
                int ID;
                ID = Convert.ToInt32(HttpContext.Current.Session["frmO_HistoryInfoInput_ID"]);
                int temp = -1;
                int 企業ID = Convert.ToInt32(HttpContext.Current.Session["frmO_BasicInfoInputCheck_企業ID"]);
                temp = frmO_HistoryInfoInput_Check_Insert(企業ID, 年度, 決算月, out temp);
                if (temp == 9)
                {
                    DataTable dt = frmO_HistoryInfoInput_GetID(企業ID, 年度, 決算月);
                    if (ID != Convert.ToInt32(dt.Rows[0]["ID"]))
                    {
                        args.IsValid = false;
                        hd_決算月2.Value = ddl_決算月.SelectedValue.ToString();
                    }
                    else
                    {
                        args.IsValid = true;
                    }
                }
               
            }
            else
            {
                int 企業ID = Convert.ToInt32(HttpContext.Current.Session["frmO_BasicInfoInputCheck_企業ID"]);
                int temp = -1;
                temp = frmO_HistoryInfoInput_Check_Insert(企業ID, 年度, 決算月, out temp);
              
                if (temp == 9)
                {
                    args.IsValid = false;
                    hd_決算月2.Value = ddl_決算月.SelectedValue.ToString();
                }
                else
                {
                    //Day la truong hop dung
                    DataTable dt = new 本社履歴Manager().frmO_HistoryInfoInput_CheckExists_企業ID_Year(企業ID, 年度);
                    if (dt.Rows.Count > 0)
                    {
                        args.IsValid = false;
                        hd_決算月2.Value = ddl_決算月.SelectedValue.ToString();
                    }
                    else
                    {
                        args.IsValid = true;
                    }
                }
            }
        }
        else
        {
            // Mode update chua xu ly
            int ID;
            if (HttpContext.Current.Session["frmO_BasicInfoRef_ID"] != null && HttpContext.Current.Session["frmO_BasicInfoRef_ID"].ToString() != "")
            {
                ID = Convert.ToInt32(HttpContext.Current.Session["frmO_BasicInfoRef_ID"]);
                int 企業ID = Convert.ToInt32(HttpContext.Current.Session["frmO_BasicInfoRef_企業ID"]);
                int temp = -1;
                temp = frmO_HistoryInfoInput_Check_Insert(企業ID, 年度, 決算月, out temp);
                if (temp == 9)
                {
                    DataTable dt = frmO_HistoryInfoInput_GetID(企業ID, 年度, 決算月);
                    if (ID != Convert.ToInt32(dt.Rows[0]["ID"]))
                    {
                        args.IsValid = false;
                        hd_決算月2.Value = ddl_決算月.SelectedValue.ToString();
                    }
                    else
                    {
                        args.IsValid = false;
                    }
                }
               
            }

        }
    }
}
